package com.example.viewflipperdemo;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.widget.AdapterViewFlipper;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.ViewFlipper;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    private ViewFlipper flipper;
    private View view;
    private AdapterViewFlipper avf_view;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        test1();
        test2();
    }

    private void test2() {
        avf_view = findViewById(R.id.avf_view);
        ArrayList<String> strings = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            strings.add("欢迎光临" + i);
        }
        ViewFlipperAdapter viewFlipperAdapter = new ViewFlipperAdapter(this, strings);
        avf_view.setAdapter(viewFlipperAdapter);
        avf_view.setAutoStart(true);

    }

    private void test1() {
        flipper = findViewById(R.id.vf);
        for (int i = 0; i < 10; i++) {
            view = View.inflate(this, R.layout.notice_item, null);
            ImageView iv_notice = view.findViewById(R.id.iv_notice);
            TextView tv_notice = view.findViewById(R.id.tv_notice);
            tv_notice.setText("通知都是假的，公司要倒闭了" + i);
            flipper.addView(view);
        }
        flipper.startFlipping();
        flipper.getInAnimation().setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}